﻿<include file='public/_meta'>


<title>添加角色 </title>
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<article class="page-container">
	<form action="{:url('index/roles/edit')}" method="post" class="form form-horizontal" id="form-admin-role-add">
		<input type="hidden" name="id" value="{$roles.id}">
		<div class="row cl">
			<label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-10">
				<input type="text" class="input-text" value="{$roles.role_name}" placeholder="" id="roleName" name="role_name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">描述：</label>
			<div class="formControls col-xs-8 col-sm-10">
				<input type="text" class="input-text" value="{$roles.role_desc}" placeholder="" id="" name="role_desc">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">网站角色：</label>
			<div class="formControls col-xs-8 col-sm-10">
				<foreach $data as $node_title>
				<dl class="permission-list">
					<dt>
						<label>
							<input type="checkbox" id="user-Character-0" name="node_title[]" value="{$node_title.id}" {:in_array($node_title.id, $menu)?'checked':''}>
							{$node_title.grop_name}</label>
					</dt>
					<dd>
						<foreach $node_title['node_next'] as $node_grop>
						<dl class="cl permission-list2">
							<dt>
								<label class="">
									<input type="checkbox" name="grop_name[]" value="{$node_grop.id}" id="user-Character-0-0" {:in_array($node_grop.id, $grop)?'checked':''}>
									{$node_grop['grop_name']}</label>
							</dt>
							<dd>
								<foreach name="node_grop['nodes']" id="nodes" key="key" >
								<label class="">
									<input type="checkbox" value="{$nodes.id}" name="node[]" id="user-Character-0-0-0" {:in_array($nodes['id'], $roles_node)?'checked':''}>
									{$nodes.node_name}</label>
								</foreach>
							</dd>
						</dl>
						</foreach>
					</dd>
				</dl>
				</foreach>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</article>
<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
	
	$("#form-admin-role-add").validate({
		rules:{
			role_name:{
				required:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				 success: function(data) { 
                if(data['code']==1){
                
                	layer.msg(data['msg'], {icon:6,time:1000},function(){

						parent.location.href = '{:url('index')}';              		
						parent.layer.close(index);
                	});

                }else{
                	layer.msg("更新失败");

                }
            }


			});
		}
	});
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>